#include <iostream>
#include <stdio.h>
#include "rectangle.h"
#include "circle.h"
#include "triangle.h"
#include "commonAlgorithms.h"
#include "binaryTree.h"
#include "linkedList.h"
#include <string>

using namespace std;
using namespace Shapes;
using namespace Algorithms;
using namespace DataStructures;

void processShapes();
void useRectangle();
void useCircle();
void useTriangle();
void processAlgorithms();
void useBinarySearch();
void processDataStructures();
void useBinaryTree();
void useLinkedList();

int main()
{
	//processShapes();
	//processAlgorithms();
	processDataStructures();

	system("pause");
}

void processShapes()
{
	int option;
	
	char tryAgain = 'Y';

	while(toupper(tryAgain) == 'Y')
	{
		cout << "Select a shape: " << endl;
		cout << "1 - Rectangle" << endl;
		cout << "2 - Triangle" << endl;
		cout << "3 - Circle" << "\n\n";
		cin >> option;
		cout << "\n";

		switch(option)
		{
		case 1:
			useRectangle();
			break;
		case 2:
			useTriangle();
			break;
		case 3:
			useCircle();
			break;
		}

		cout << "\nTry Again? (Y or N)" << endl;
		cin >> tryAgain;	

		cout << endl;
	}
}

void useRectangle()
{
	double width, height;

	cout << "Enter a width: " << "\n\n";
	cin >> width;

	cout << "\nEnter a height:" << "\n\n";
	cin >> height;
	cout << "\n\n";

	Rectangle* rect = new Rectangle(width, height);
	(*rect).draw(false);
	
	cout << "\nRectangle" << endl;
	cout << "Width: " << (*rect).getWidth() << endl;
	cout << "Height: " << (*rect).getHeight() << endl;

	cout << "Perimeter: " << (*rect).perimeter() << endl;
	cout << "Area: " << (*rect).area() << endl;	
	cout << "Diagonal: " << (*rect).diagonal() << "\n";
	
	delete rect;	
}

void useCircle()
{
	double radius;

	cout << "Enter a radius: " << "\n\n";
	cin >> radius;
	
	Circle* circ = new Circle(radius);
	(*circ).draw(false);

	cout << "\nCircle" << endl;
	cout << "Radius: " << (*circ).getRadius() << endl;	
	cout << "Circumference: " << (*circ).circumference() << endl;
	cout << "Diameter: " << (*circ).diameter() << endl;
	cout << "Area: " << (*circ).area() << "\n";	

	delete circ;	
}

void useTriangle()
{
	double base, height;

	cout << "Enter a base: " << "\n\n";
	cin >> base;

	cout << "\nEnter a height:" << "\n\n";
	cin >> height;
	
	Triangle* tri = new Triangle(base, height);
	(*tri).draw();
	
	cout << "\nTriangle" << endl;
	cout << "Base: " << (*tri).getBase() << endl;
	cout << "Height: " << (*tri).getHeight() << endl;
		
	cout << "Area: " << (*tri).area() << endl;	
		
	delete tri;		
}

void processAlgorithms()
{
	useBinarySearch();
}

void useBinarySearch()
{
	int arr[15] = {1, 3, 6, 7, 32, 33, 45, 54, 61, 70, 73, 80, 91, 99, 100 };
	int numberToFind;

	cout << "Array: " << "{1, 3, 6, 7, 32, 33, 45, 54, 61, 70, 73, 80, 91, 99 }" << endl;
	cout << "Which item to find: " << endl;
	cin >> numberToFind;
		
	if(CommonAlgorithms::BinarySearch(arr, 0, 14, numberToFind))
		cout << "Found item: " << numberToFind << endl;
	else
		cout << "Did not find item: " << numberToFind << endl;
}

void processDataStructures()
{
	//useBinaryTree();
	useLinkedList();
}

void useBinaryTree()
{
	BinaryTree* tree = new BinaryTree();
	(*tree).Insert(2);
	(*tree).Insert(2);
	(*tree).Insert(2);
	(*tree).Insert(2);
	(*tree).Insert(2);

	(*tree).PrintTree();
}

void useLinkedList()
{
	LinkedList* list = new LinkedList();
	
	// Limit 2631 recursively
	for(int i = 0; i < 3000; i++)
		(*list).Insert(true, i);
	
	(*list).PrintList(true);
}